home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Metarchivos / CreateMetafileMemory / CreateMetafileMemory.cs next >
Encoding:
Text File  |  2002-05-27  |  1.6 KB  |  53 lines

  1. //---------------------------------------------------
  2. // CreateMetafileMemory.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.IO;
  8. using System.Windows.Forms;
  9.  
  10. class CreateMetafileMemory: PrintableForm
  11. {
  12.      readonly MemoryStream ms = new MemoryStream();
  13.  
  14.      public new static void Main()
  15.      {
  16.           Application.Run(new CreateMetafileMemory());
  17.      }
  18.      public CreateMetafileMemory()
  19.      {
  20.           Text = "Crear metarchivo (Memoria)";
  21.  
  22.                // Crear el metarchivo.
  23.  
  24.           Graphics grfx = CreateGraphics();
  25.           IntPtr ipHdc = grfx.GetHdc();
  26.  
  27.           Metafile mf = new Metafile(ms, ipHdc); 
  28.  
  29.           grfx.ReleaseHdc(ipHdc);
  30.           grfx.Dispose();
  31.  
  32.                // Dibujar sobre el metarchivo.
  33.  
  34.           grfx = Graphics.FromImage(mf);
  35.  
  36.           grfx.FillEllipse(Brushes.Gray, 0, 0, 100, 100);
  37.           grfx.DrawEllipse(Pens.Black, 0, 0, 100, 100);
  38.           grfx.FillEllipse(Brushes.Blue, 20, 20, 20, 20);
  39.           grfx.FillEllipse(Brushes.Blue, 60, 20, 20, 20);
  40.           grfx.DrawArc(new Pen(Color.Red, 10), 20, 20, 60, 60, 30, 120);
  41.           grfx.Dispose();
  42.      }
  43.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  44.      {
  45.           ms.Position = 0;
  46.           Metafile mf = new Metafile(ms);
  47.  
  48.           for (int y = 0; y < cy; y += mf.Height)
  49.           for (int x = 0; x < cx; x += mf.Width)
  50.                grfx.DrawImage(mf, x, y, mf.Width, mf.Height);
  51.      }
  52. }
  53.